/***********************************************************************
 * Module:  Question.java
 * Author:  DAC
 * Purpose: Defines the Class Question
 ***********************************************************************/
package com.group1.model;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

/** @pdOid a323ac32-4cb9-4618-b76e-f47cb78d9d7c */
public class Question {
   /** @pdOid 70561e79-a5c4-4f3c-a5ae-37f5d860c989 */
   protected void finalize() {
      // TODO: implement
   }
   
   /** @pdOid 2d934daf-3093-4d41-baf0-e91b16e8641b */
   public Integer questionId;
   /** @pdOid 6bf7fd98-2a65-4ed5-b315-643e7f3d3dc0 */
   public java.lang.String questionDesc;
   /** @pdOid ef1e6ec8-de72-444f-9219-b178921d18d6 */
   public java.lang.String questionType;
   /** @pdOid 013fb6e3-f736-4fa6-ad5d-7bc778978ddc */
   public int questionLevel;
   
   /** @pdRoleInfo migr=no name=AnswerItem assc=answerItemsOfQuestions coll=java.util.Collection impl=java.util.HashSet mult=0..* */
   public java.util.Collection<AnswerItem> answerItem;
   /** @pdRoleInfo migr=no name=QuestionImage assc=figuresOfQuestions coll=java.util.Collection impl=java.util.HashSet mult=0..* */
   public java.util.Collection<QuestionImage> questionImage;
   /** @pdRoleInfo migr=no name=QuestionShortcut assc=shortcutsToQuestions coll=java.util.Collection impl=java.util.HashSet mult=0..* */
   public java.util.Collection<QuestionShortcut> questionShortcut;
   /** @pdRoleInfo migr=no name=TestItem assc=questionsCorrespondingToTestItem coll=java.util.Collection impl=java.util.HashSet mult=0..* */
   public java.util.Collection<TestItem> testItem;
   /** @pdRoleInfo migr=no name=Topic assc=questionsInsideTopics mult=0..1 side=A */
   public Topic topic;
   /** @pdRoleInfo migr=no name=Lecturer assc=creatorOfQuestions mult=0..1 side=A */
   public Lecturer lecturer;
   
   /** @param questionID 
    * @param questionDesc 
    * @param questionType 
    * @param questionLevel 
    * @param topicID 
    * @param lecturerID
    * @pdOid deab2d13-bed2-4186-888b-54f4750e6615 */
   public Question(Integer questionID, String questionDesc, String questionType, int questionLevel, long topicID, String lecturerID) {
      
	   this.questionId = questionID;
	   this.questionDesc = questionDesc;
	   this.questionType = questionType;
	   this.questionLevel = questionLevel;
	   this.topic.topicId = (int) topicID;
	   this.lecturer.lecturerId = lecturerID;
   }
   
   
   /** @param session
    * @pdOid ccd1c3ef-4ecc-4003-93d9-d41327c673ce */
   public static List<Question> getAllQuestion(Session session) {
      Query query = session.createQuery("from Question");
      List<Question> listOfQuestion = query.list();
      return listOfQuestion;
   }
   
   /** @param questionID 
    * @param session
    * @pdOid b752b35e-a11d-4040-a793-6b27fc38da00 */
   public static Question getQuestionByID(Integer questionID, Session session) {
      // TODO: implement
      return (Question) session.get(Question.class, questionID);
   }
   
   /** @param topicID 
    * @param session
    * @pdOid 54c069c5-5ba1-4cf1-9274-179f3d9b4eaf */
   public static List<Question> getQuestionByTopic(Integer topicID, Session session) {
	  Query query = session.createQuery("from Question where TOPIC_ID = '" + topicID + "'" );
	  List<Question> list = query.list();
      return list;
   }
   
   /** @param lecturerID 
    * @param session
    * @pdOid 72a8f6ce-ca1e-4c04-8e44-401a007cd1c5 */
   public static List<Question> getQuestionOfLecturer(String lecturerID, Session session) {
	   Query query = session.createQuery("from Question where LECTURER_ID = '" + lecturerID + "'" );
	   List<Question> list = query.list();
      return list;
   }
   
   /** @pdOid 08e497fd-43a7-4793-a553-50594899c6da */
   public Integer getQuestionId() {
      return questionId;
   }
   
   /** @param newQuestionId
    * @pdOid 294a675e-e0d3-4a54-bb6f-340b425e24ef */
   public void setQuestionId(Integer newQuestionId) {
      questionId = newQuestionId;
   }
   
   /** @pdOid e5d74a22-6a61-4909-a7fc-8e9cf9108aae */
   public java.lang.String getQuestionDesc() {
      return questionDesc;
   }
   
   /** @param newQuestionDesc
    * @pdOid 16f63d1f-3244-4c3b-b002-9b2ed48df074 */
   public void setQuestionDesc(java.lang.String newQuestionDesc) {
      questionDesc = newQuestionDesc;
   }
   
   /** @pdOid d8203ab4-e9b9-4632-81b9-409e2c4ef098 */
   public java.lang.String getQuestionType() {
      return questionType;
   }
   
   /** @param newQuestionType
    * @pdOid 871d30c7-3098-44dc-a0da-b98852b8e0c1 */
   public void setQuestionType(java.lang.String newQuestionType) {
      questionType = newQuestionType;
   }
   
   /** @pdOid 188d578c-d664-4e2d-8935-0d8d3bee2ab2 */
   public int getQuestionLevel() {
      return questionLevel;
   }
   
   /** @param newQuestionLevel
    * @pdOid d215f341-c9c1-4611-85f6-58c39b970858 */
   public void setQuestionLevel(int newQuestionLevel) {
      questionLevel = newQuestionLevel;
   }
   
   /** @pdOid bb6cc2b8-800a-4dc5-83e0-c773878336b3 */
   public Question() {
      // TODO: implement
   }
   
   
   /** @pdGenerated default getter */
   public java.util.Collection<AnswerItem> getAnswerItem() {
      if (answerItem == null)
         answerItem = new java.util.HashSet<AnswerItem>();
      return answerItem;
   }
   
   /** @pdGenerated default iterator getter */
   public java.util.Iterator getIteratorAnswerItem() {
      if (answerItem == null)
         answerItem = new java.util.HashSet<AnswerItem>();
      return answerItem.iterator();
   }
   
   /** @pdGenerated default setter
     * @param newAnswerItem */
   public void setAnswerItem(java.util.Collection<AnswerItem> newAnswerItem) {
      removeAllAnswerItem();
      for (java.util.Iterator iter = newAnswerItem.iterator(); iter.hasNext();)
         addAnswerItem((AnswerItem)iter.next());
   }
   
   /** @pdGenerated default add
     * @param newAnswerItem */
   public void addAnswerItem(AnswerItem newAnswerItem) {
      if (newAnswerItem == null)
         return;
      if (this.answerItem == null)
         this.answerItem = new java.util.HashSet<AnswerItem>();
      if (!this.answerItem.contains(newAnswerItem))
      {
         this.answerItem.add(newAnswerItem);
         newAnswerItem.setQuestion(this);      
      }
   }
   
   /** @pdGenerated default remove
     * @param oldAnswerItem */
   public void removeAnswerItem(AnswerItem oldAnswerItem) {
      if (oldAnswerItem == null)
         return;
      if (this.answerItem != null)
         if (this.answerItem.contains(oldAnswerItem))
         {
            this.answerItem.remove(oldAnswerItem);
            oldAnswerItem.setQuestion((Question)null);
         }
   }
   
   /** @pdGenerated default removeAll */
   public void removeAllAnswerItem() {
      if (answerItem != null)
      {
         AnswerItem oldAnswerItem;
         for (java.util.Iterator iter = getIteratorAnswerItem(); iter.hasNext();)
         {
            oldAnswerItem = (AnswerItem)iter.next();
            iter.remove();
            oldAnswerItem.setQuestion((Question)null);
         }
      }
   }
   /** @pdGenerated default getter */
   public java.util.Collection<QuestionImage> getQuestionImage() {
      if (questionImage == null)
         questionImage = new java.util.HashSet<QuestionImage>();
      return questionImage;
   }
   
   /** @pdGenerated default iterator getter */
   public java.util.Iterator getIteratorQuestionImage() {
      if (questionImage == null)
         questionImage = new java.util.HashSet<QuestionImage>();
      return questionImage.iterator();
   }
   
   /** @pdGenerated default setter
     * @param newQuestionImage */
   public void setQuestionImage(java.util.Collection<QuestionImage> newQuestionImage) {
      removeAllQuestionImage();
      for (java.util.Iterator iter = newQuestionImage.iterator(); iter.hasNext();)
         addQuestionImage((QuestionImage)iter.next());
   }
   
   /** @pdGenerated default add
     * @param newQuestionImage */
   public void addQuestionImage(QuestionImage newQuestionImage) {
      if (newQuestionImage == null)
         return;
      if (this.questionImage == null)
         this.questionImage = new java.util.HashSet<QuestionImage>();
      if (!this.questionImage.contains(newQuestionImage))
      {
         this.questionImage.add(newQuestionImage);
         newQuestionImage.setQuestion(this);      
      }
   }
   
   /** @pdGenerated default remove
     * @param oldQuestionImage */
   public void removeQuestionImage(QuestionImage oldQuestionImage) {
      if (oldQuestionImage == null)
         return;
      if (this.questionImage != null)
         if (this.questionImage.contains(oldQuestionImage))
         {
            this.questionImage.remove(oldQuestionImage);
            oldQuestionImage.setQuestion((Question)null);
         }
   }
   
   /** @pdGenerated default removeAll */
   public void removeAllQuestionImage() {
      if (questionImage != null)
      {
         QuestionImage oldQuestionImage;
         for (java.util.Iterator iter = getIteratorQuestionImage(); iter.hasNext();)
         {
            oldQuestionImage = (QuestionImage)iter.next();
            iter.remove();
            oldQuestionImage.setQuestion((Question)null);
         }
      }
   }
   /** @pdGenerated default getter */
   public java.util.Collection<QuestionShortcut> getQuestionShortcut() {
      if (questionShortcut == null)
         questionShortcut = new java.util.HashSet<QuestionShortcut>();
      return questionShortcut;
   }
   
   /** @pdGenerated default iterator getter */
   public java.util.Iterator getIteratorQuestionShortcut() {
      if (questionShortcut == null)
         questionShortcut = new java.util.HashSet<QuestionShortcut>();
      return questionShortcut.iterator();
   }
   
   /** @pdGenerated default setter
     * @param newQuestionShortcut */
   public void setQuestionShortcut(java.util.Collection<QuestionShortcut> newQuestionShortcut) {
      removeAllQuestionShortcut();
      for (java.util.Iterator iter = newQuestionShortcut.iterator(); iter.hasNext();)
         addQuestionShortcut((QuestionShortcut)iter.next());
   }
   
   /** @pdGenerated default add
     * @param newQuestionShortcut */
   public void addQuestionShortcut(QuestionShortcut newQuestionShortcut) {
      if (newQuestionShortcut == null)
         return;
      if (this.questionShortcut == null)
         this.questionShortcut = new java.util.HashSet<QuestionShortcut>();
      if (!this.questionShortcut.contains(newQuestionShortcut))
      {
         this.questionShortcut.add(newQuestionShortcut);
         newQuestionShortcut.setQuestion(this);      
      }
   }
   
   /** @pdGenerated default remove
     * @param oldQuestionShortcut */
   public void removeQuestionShortcut(QuestionShortcut oldQuestionShortcut) {
      if (oldQuestionShortcut == null)
         return;
      if (this.questionShortcut != null)
         if (this.questionShortcut.contains(oldQuestionShortcut))
         {
            this.questionShortcut.remove(oldQuestionShortcut);
            oldQuestionShortcut.setQuestion((Question)null);
         }
   }
   
   /** @pdGenerated default removeAll */
   public void removeAllQuestionShortcut() {
      if (questionShortcut != null)
      {
         QuestionShortcut oldQuestionShortcut;
         for (java.util.Iterator iter = getIteratorQuestionShortcut(); iter.hasNext();)
         {
            oldQuestionShortcut = (QuestionShortcut)iter.next();
            iter.remove();
            oldQuestionShortcut.setQuestion((Question)null);
         }
      }
   }
   /** @pdGenerated default getter */
   public java.util.Collection<TestItem> getTestItem() {
      if (testItem == null)
         testItem = new java.util.HashSet<TestItem>();
      return testItem;
   }
   
   /** @pdGenerated default iterator getter */
   public java.util.Iterator getIteratorTestItem() {
      if (testItem == null)
         testItem = new java.util.HashSet<TestItem>();
      return testItem.iterator();
   }
   
   /** @pdGenerated default setter
     * @param newTestItem */
   public void setTestItem(java.util.Collection<TestItem> newTestItem) {
      removeAllTestItem();
      for (java.util.Iterator iter = newTestItem.iterator(); iter.hasNext();)
         addTestItem((TestItem)iter.next());
   }
   
   /** @pdGenerated default add
     * @param newTestItem */
   public void addTestItem(TestItem newTestItem) {
      if (newTestItem == null)
         return;
      if (this.testItem == null)
         this.testItem = new java.util.HashSet<TestItem>();
      if (!this.testItem.contains(newTestItem))
      {
         this.testItem.add(newTestItem);
         newTestItem.setQuestion(this);      
      }
   }
   
   /** @pdGenerated default remove
     * @param oldTestItem */
   public void removeTestItem(TestItem oldTestItem) {
      if (oldTestItem == null)
         return;
      if (this.testItem != null)
         if (this.testItem.contains(oldTestItem))
         {
            this.testItem.remove(oldTestItem);
            oldTestItem.setQuestion((Question)null);
         }
   }
   
   /** @pdGenerated default removeAll */
   public void removeAllTestItem() {
      if (testItem != null)
      {
         TestItem oldTestItem;
         for (java.util.Iterator iter = getIteratorTestItem(); iter.hasNext();)
         {
            oldTestItem = (TestItem)iter.next();
            iter.remove();
            oldTestItem.setQuestion((Question)null);
         }
      }
   }
   /** @pdGenerated default parent getter */
   public Topic getTopic() {
      return topic;
   }
   
   /** @pdGenerated default parent setter
     * @param newTopic */
   public void setTopic(Topic newTopic) {
      if (this.topic == null || !this.topic.equals(newTopic))
      {
         if (this.topic != null)
         {
            Topic oldTopic = this.topic;
            this.topic = null;
            oldTopic.removeQuestion(this);
         }
         if (newTopic != null)
         {
            this.topic = newTopic;
            this.topic.addQuestion(this);
         }
      }
   }
   /** @pdGenerated default parent getter */
   public Lecturer getLecturer() {
      return lecturer;
   }
   
   /** @pdGenerated default parent setter
     * @param newLecturer */
   public void setLecturer(Lecturer newLecturer) {
      if (this.lecturer == null || !this.lecturer.equals(newLecturer))
      {
         if (this.lecturer != null)
         {
            Lecturer oldLecturer = this.lecturer;
            this.lecturer = null;
            oldLecturer.removeQuestion(this);
         }
         if (newLecturer != null)
         {
            this.lecturer = newLecturer;
            this.lecturer.addQuestion(this);
         }
      }
   }

}